package com.gimi.cloud.jimi.common.utils;

import java.math.BigDecimal;

/**
 * 数学计算工具类
 * @author xiankejin
 * @date 2017-08-01
 */
public class CaculateUtil {

	/**
	 * 计算包的总利息
	 * @param interestRate 利率
	 * @param activityRate 活动利率
	 * @param tansMoney 交易金额、本金
	 * @param periods 包周期
	 * @return
	 */
	public static BigDecimal calculateTotalRateMoney(BigDecimal interestRate, BigDecimal activityRate, BigDecimal tansMoney, Integer periods) {
		if(activityRate == null) {
			activityRate = BigDecimal.ZERO;
		}
		BigDecimal rateByYear = (interestRate.add(activityRate)).divide(new BigDecimal(365),10,BigDecimal.ROUND_DOWN);
		BigDecimal totalRateMoney = rateByYear.multiply(new BigDecimal(periods)).multiply(tansMoney);
		totalRateMoney = totalRateMoney.setScale(2, BigDecimal.ROUND_DOWN);
		return totalRateMoney;
	}
	
}
